home *** CD-ROM | disk | FTP | other *** search
- function cpvw_response(_1,_2,_3,_4,_5){
- this.xmlDoc=_1;
- this.responseText=_2;
- this.responseHeaders=_3;
- this.statusMesg=_4;
- this.hasErrors=(_5!=null);
- this.file=null;
- }
- function cpvw_httpClient(_6){
- this.objAct=_6;
- this.headers=null;
- this.channel=null;
- this.observerSerivce=null;
- this.timer=null;
- }
- cpvw_httpClient.prototype={topic:"http-on-modify-request",getObject:function(){
- return Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Components.interfaces.nsIXMLHttpRequest);
- },parseHeaders:function(_7){
- var _8=[];
- var _9=_7.split("\n");
- for(var i=0;i<_9.length;i++){
- var _b=_9[i];
- var _c=_b.match(/(.*?):(.*)/);
- if(_c!=null){
- var _d=_c[1];
- var _e=_c[2];
- _8[_d]=_e;
- }
- }
- return _8;
- },QueryInterface:function(_f){
- if(_f.equals(Components.interfaces.nsISupports)||_f.equals(Components.interfaces.nsIObserver)||_f.equals(Components.interfaces.nsITimerCallback)){
- return this;
- }
- throw Components.results.NS_ERROR_NO_INTERFACE;
- },observe:function(_10,_11,_12){
- if(_11=="xpcom-shutdown"){
- this.clean();
- }
- if(_11!=this.topic||_10!=this.channel){
- return;
- }
- if(this.headers instanceof Array){
- for(var i=0;i<this.headers.length;i++){
- this.channel.setRequestHeader(this.headers[i].name,this.headers[i].value,false);
- }
- }
- this.clean();
- },notify:function(){
- this.clean();
- },clean:function(){
- var _14=Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
- _14.removeObserver(this,this.topic);
- if(this.timer){
- this.timer.cancel();
- this.timer=null;
- }
- },doRequest:function(_15,_16,_17,_18,_19,_1a,_1b){
- var _1c=this;
- try{
- var _1d=this.getObject();
- if(_17!=""){
- _17="?"+_17;
- }
- var _1e=_16+_17;
- _1d.open(_15,_1e,!_19);
- _1d.channel.loadFlags|=Components.interfaces.nsIRequest.LOAD_BYPASS_CACHE;
- if(_15=="POST"){
- _1d.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=utf-8");
- }
- var _1f=_1d.channel.QueryInterface(Components.interfaces.nsIHttpChannel);
- _1f.redirectionLimit=0;
- this.channel=_1f;
- this.headers=_1a;
- var _20=Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
- _20.addObserver(this,this.topic,false);
- _20.addObserver(this,"xpcom-shutdown",false);
- this.timer=Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer);
- this.timer.initWithCallback(this,15000,this.timer.TYPE_ONE_SHOT);
- this.redirectCount=0;
- _1d.send(_18);
- var _21=Components.classes["@mozilla.org/xmlextras/domparser;1"].createInstance(Components.interfaces.nsIDOMParser);
- if(_19){
- if(_1d.status>=200&&_1d.status<300){
- var _22=_21.parseFromString(_1d.responseText,"text/xml");
- var _23=new cpvw_response(_22,_1d.responseText,_1c.parseHeaders(_1d.getAllResponseHeaders()));
- if(_1b){
- _1b.call(_1c.objAct,_23);
- }
- return _23;
- }else{
- var _24="Error connecting! Try again - "+_1d.status+" "+_1d.statusText;
- var _22=null;
- try{
- _22=_21.parseFromString(_1d.responseText,"text/xml");
- }
- catch(ex2){
- _22=null;
- _24=ex2;
- }
- if(_22!=null&&_22.getElementsByTagName("Message")[0]){
- _24=_22.getElementsByTagName("Message")[0].firstChild.nodeValue;
- }
- var _23=new cpvw_response(_22,_1d.responseText,_1c.parseHeaders(_1d.getAllResponseHeaders()),_24,true);
- if(_1b){
- _1b.call(_1c.objAct,_23);
- }
- return _23;
- }
- }else{
- _1d.onreadystatechange=function(){
- if(_1d.readyState!=4){
- return;
- }else{
- if(_1d.status>=200&&_1d.status<300){
- var _25=_1d.responseXML;
- var _26=new cpvw_response(_25,_1d.responseText,_1c.parseHeaders(_1d.getAllResponseHeaders()));
- if(_1b){
- _1b.call(_1c.objAct,_26);
- }
- return _26;
- }else{
- if(_1d.status>=300&&_1d.status<400){
- var _27=_1c.parseHeaders(_1d.getAllResponseHeaders());
- if(_27["Location"]!=null&&_1c.redirectCount<3){
- _1c.redirectCount++;
- _1c.doRequest(_15,_27["Location"],_17,_18,_19,_1a,_1b);
- return;
- }
- }
- var _28="Error connecting! Try again - "+_1d.status+" "+_1d.statusText;
- var _25=null;
- try{
- _25=_21.parseFromString(_1d.responseText,"text/xml");
- }
- catch(ex2){
- _25=null;
- _28=ex2;
- }
- if(_25!=null&&_25.getElementsByTagName("Message")[0]){
- _28=_25.getElementsByTagName("Message")[0].firstChild.nodeValue;
- }
- var _26=new cpvw_response(_25,_1d.responseText,_1d.getAllResponseHeaders(),_28,true);
- if(_1b){
- _1b.call(_1c.objAct,_26);
- }
- return false;
- }
- }
- };
- }
- }
- catch(ex){
- var _23=new cpvw_response(null,"",null,ex,true);
- if(_1b){
- _1b.call(_1c.objAct,_23);
- }
- }
- }};
-
-